package com.buildings.activity.table;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

import com.buildings.R;
import com.buildings.api.Api;
import com.buildings.api.Constant;
import com.buildings.base.BaseActivity;
import com.buildings.base.BaseApplication;
import com.buildings.base.JsonBean;
import com.buildings.bean.FaultTypeBean;
import com.buildings.bean.GeoGeomorphySvyPointDbEntity;
import com.buildings.bean.GeologicalSvyPlanningPtEntity;
import com.buildings.bean.LoginBean;
import com.buildings.bean.StratigraphySvyPointDbEntity;
import com.buildings.bean.StratigraphySvyPointEntity;
import com.buildings.http.BaseCallBack;
import com.buildings.http.JsonBuilder;
import com.buildings.http.MyHttpClient;
import com.buildings.util.CustomToast;
import com.buildings.util.DialogUtils;
import com.buildings.util.FileUtil;
import com.buildings.util.HYDialogUtils;
import com.buildings.util.HYImageUtils;
import com.buildings.util.PhotoRecycleBuild;
import com.buildings.util.SPUtil;
import com.buildings.util.StringUtil;
import com.buildings.util.TabTitleBuilder;
import com.buildings.view.ShowBottomDialog;
import com.google.gson.Gson;
import com.zr.earthquate.db.greendao.DaoSession;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

//地层观测点-点
public class StratigraphySvyPointActivity extends BaseActivity {
    @BindView(R.id.ll_tab_title)
    LinearLayout llTabTitle;
    @BindView(R.id.rv_pics)
    RecyclerView rvPics;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right_text)
    TextView tvRightText;

    @BindView(R.id.et_id)
    EditText etId;
    @BindView(R.id.et_fieldid)
    EditText etFieldid;
    @BindView(R.id.et_geologicalsvypointid)
    EditText etGeologicalsvypointid;
    @BindView(R.id.et_stratigraphyname)
    EditText etStratigraphyname;
    @BindView(R.id.et_strike)
    EditText etStrike;
    @BindView(R.id.et_dip)
    EditText etDip;
    @BindView(R.id.et_clination)
    EditText etClination;
    @BindView(R.id.tv_touchrelation)
    TextView tvTouchrelation;
    @BindView(R.id.et_touchredescription)
    EditText etTouchredescription;
    @BindView(R.id.et_thickness)
    EditText etThickness;
    @BindView(R.id.et_stratigraphydescription)
    EditText etStratigraphydescription;
    @BindView(R.id.tv_isreversed)
    TextView tvIsreversed;
    @BindView(R.id.et_photoAiid)
    EditText etPhotoAiid;
    @BindView(R.id.tv_photoviewingto)
    TextView tvPhotoviewingto;
    @BindView(R.id.et_photographer)
    EditText etPhotographer;
    @BindView(R.id.et_datasource)
    EditText etDatasource;
    @BindView(R.id.tv_ismodifyworkmap)
    TextView tvIsmodifyworkmap;
    @BindView(R.id.tv_isinmap)
    TextView tvIsinmap;
    @BindView(R.id.et_lastangle)
    EditText etLastangle;
    @BindView(R.id.et_remark)
    EditText etRemark;

    @BindView(R.id.ll_visibile)
    LinearLayout llVisibile;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.tv_visibile)
    TextView tvVisibile;
    private DaoSession daoSession;

    private TabTitleBuilder tabTitleBuilder;
    private PhotoRecycleBuild photoRecycleBuild;
    private Dialog myDialog;
    private String urlArr;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startigraphy);
        ButterKnife.bind(this);
        daoSession = BaseApplication.getInstance().getDaoSession();
        tabTitleBuilder = new TabTitleBuilder(llTabTitle, this);
        initView();
    }

    private String type;
    private String taskId = "";
    private String projectId = "";
    private String projectName = "";
    private String taskName = "";
    private boolean isOnline;
    private int joninType;
    private String uuid;
    private long _id = -1;

    public void initView() {
        joninType = getIntent().getIntExtra("joninType", 1);
        photoRecycleBuild = new PhotoRecycleBuild(this, rvPics, joninType);
        if (joninType != 2) {
            tvTitle.setText("地层观测点-点");
            tvRightText.setText("保存");
            double x = getIntent().getDoubleExtra("x", 0.0);
            double y = getIntent().getDoubleExtra("y", 0.0);
            type = getIntent().getStringExtra("type");
            taskId = getIntent().getStringExtra("taskId");
            projectId = getIntent().getStringExtra("projectId");
            projectName = getIntent().getStringExtra("projectName");
            taskName = getIntent().getStringExtra("taskName");
            isOnline = getIntent().getBooleanExtra("isOnLine", true);
            if (TextUtils.isEmpty(type)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(taskId)){
                finish();
            }
            if (isOnline && TextUtils.isEmpty(projectId)){
                finish();
            }
            tabTitleBuilder.setLat(x);
            tabTitleBuilder.setLon(y);
            if (getIntent().hasExtra("_id")) {
                _id = getIntent().getLongExtra("_id", -1);
                setLocalData(_id);
            }
            if (1 == Constant.IS_ON_LINE){
                btnSubmit.setVisibility(View.VISIBLE);
            }else {
                btnSubmit.setVisibility(View.GONE);
            }
        } else {
            isOnline = getIntent().getBooleanExtra("isOnLine", false);
            if (1 == Constant.IS_ON_LINE){
                tvTitle.setText("地层观测点-点详情");
                uuid = getIntent().getStringExtra("uuid");
                tabTitleBuilder.setEnabled();
                setEnableFalse();
                getDetailHttp();
                btnSubmit.setVisibility(View.GONE);
            }else {
                tvTitle.setText("地层观测点-点");
                tvRightText.setText("保存");
                uuid = getIntent().getStringExtra("uuid");
                if (getIntent().hasExtra("_id")) {
                    _id = getIntent().getLongExtra("_id", -1);
                    setLocalData(_id);
                }
                btnSubmit.setVisibility(View.GONE);
            }

        }
    }

    public void setLocalData(long a) {
        if (a == -1) {
            return;
        }
        List<StratigraphySvyPointDbEntity> students = daoSession.loadAll(StratigraphySvyPointDbEntity.class);
        for (StratigraphySvyPointDbEntity stratigraphySvyPoStringDbEntity : students) {
            if (a == stratigraphySvyPoStringDbEntity.get_id()) {
                setDetail(stratigraphySvyPoStringDbEntity);
            }
        }
    }

    private StratigraphySvyPointDbEntity stratigraphySvyPoStringDbEntity;


    private void setEnableFalse() {
        etId.setEnabled(false);
        etGeologicalsvypointid.setEnabled(false);
        etFieldid.setEnabled(false);
        etStratigraphyname.setEnabled(false);
        etStrike.setEnabled(false);
        etDip.setEnabled(false);
        etClination.setEnabled(false);
        tvTouchrelation.setEnabled(false);
        etTouchredescription.setEnabled(false);
        etThickness.setEnabled(false);
        etStratigraphydescription.setEnabled(false);
        tvIsreversed.setEnabled(false);
        etPhotoAiid.setEnabled(false);
        tvPhotoviewingto.setEnabled(false);
        etPhotographer.setEnabled(false);
        etDatasource.setEnabled(false);
        tvIsmodifyworkmap.setEnabled(false);
        tvIsinmap.setEnabled(false);
        etLastangle.setEnabled(false);
        etRemark.setEnabled(false);
    }

    @OnClick({R.id.iv_back, R.id.tv_right_text, R.id.iv_faultstrike_hint, R.id.iv_dip, R.id.iv_clination
            , R.id.tv_ismodifyworkmap, R.id.tv_isreversed, R.id.tv_isinmap, R.id.tv_touchrelation
            , R.id.tv_photoviewingto, R.id.tv_visibile, R.id.btn_submit,R.id.iv_id_hint})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_touchrelation:
                FaultTypeBean faultTypeBean1 = new Gson().fromJson(JsonBean.StraTouchTypeCVD, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean1, "StraTouchTypeCVD");
                break;
            case R.id.tv_visibile:
                if (llVisibile.getVisibility() == View.VISIBLE) {
                    llVisibile.setVisibility(View.GONE);
                    tvVisibile.setText("显示更多");
                } else {
                    llVisibile.setVisibility(View.VISIBLE);
                    tvVisibile.setText("隐藏更多");
                }
                break;
            case R.id.tv_photoviewingto:
                FaultTypeBean faultTypeBean2 = new Gson().fromJson(JsonBean.CVD_16_Direction, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean2, "CVD-16-Direction");
                break;

            case R.id.tv_ismodifyworkmap:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            tvIsmodifyworkmap.setText("是");
                        } else {
                            tvIsmodifyworkmap.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.tv_isreversed:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            tvIsreversed.setText("是");
                        } else {
                            tvIsreversed.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.tv_isinmap:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            tvIsinmap.setText("是");
                        } else {
                            tvIsinmap.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.iv_faultstrike_hint:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~360"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.iv_dip:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~360"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.iv_clination:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~90"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.tv_right_text:
                //TODO 调用保存表单接口
                save();
                break;
            case R.id.btn_submit:
                submit();
                break;
            case R.id.iv_id_hint:
                HYDialogUtils.showCommonAlertDialog(this, "长度17位，前9位，行政区划代码6位+3位专题号，后8位自定义编码，字母数字均可，不足8位#补齐\n" +
                                "3位专题号，用户自己设置。一般就是100，101，102...,201,202"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
        }
    }

    private void save() {
        StratigraphySvyPointDbEntity stratigraphySvyPointDbEntity = new StratigraphySvyPointDbEntity();
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();
        String id = etId.getText().toString().trim();
        String geologicalsvypointid = etGeologicalsvypointid.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String stratigraphyname = etStratigraphyname.getText().toString().trim();
        String strike = etStrike.getText().toString().trim();
        String dip = etDip.getText().toString().trim();
        String clination = etClination.getText().toString().trim();
        String touchrelation = tvTouchrelation.getText().toString().trim();
        String touchredescription = etTouchredescription.getText().toString().trim();
        String thickness = etThickness.getText().toString().trim();
        String stratigraphydescription = etStratigraphydescription.getText().toString().trim();
        String isreversed = tvIsreversed.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photoviewingto = tvPhotoviewingto.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String datasource = etDatasource.getText().toString().trim();
        String ismodifyworkmap = tvIsmodifyworkmap.getText().toString().trim();
        String isinmap = tvIsinmap.getText().toString().trim();
        String lastangle = etLastangle.getText().toString().trim();
        String remark = etRemark.getText().toString().trim();
        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入地层点编号");
            return;
        }
        if (id.length() != 17){
            Toast("请录入正确的地层点编号");
            return;
        }
        if (TextUtils.isEmpty(fieldid)) {
            Toast("野外编号");
            return;
        }

        if (!TextUtils.isEmpty(strike)) {
            double d1 = Double.parseDouble(strike);
            if (d1 < 0 || d1 > 360) {
                Toast("走向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(strike)) {
            double d2 = Double.parseDouble(dip);
            if (d2 < 0 || d2 > 360) {
                Toast("实测倾向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(strike)) {
            double d3 = Double.parseDouble(clination);
            if (d3 < 0 || d3 > 90) {
                Toast("倾角角度值范围 0 ~ 90");
                return;
            }
        }
        stratigraphySvyPointDbEntity.setProvince(province);
        stratigraphySvyPointDbEntity.setCity(city);
        stratigraphySvyPointDbEntity.setArea(area);
        stratigraphySvyPointDbEntity.setLat(lat);
        stratigraphySvyPointDbEntity.setLon(lon);
        stratigraphySvyPointDbEntity.setTown(buildingAddress);
        stratigraphySvyPointDbEntity.setId(id);
        stratigraphySvyPointDbEntity.setGeologicalsvypointid(geologicalsvypointid);
        stratigraphySvyPointDbEntity.setFieldid(fieldid);
        stratigraphySvyPointDbEntity.setStratigraphyname(stratigraphyname);
        stratigraphySvyPointDbEntity.setStrike(strike);
        stratigraphySvyPointDbEntity.setDip(dip);
        stratigraphySvyPointDbEntity.setClination(clination);
        stratigraphySvyPointDbEntity.setTouchrelation(null == dataBean ?
                null == stratigraphySvyPoStringDbEntity ? "" : stratigraphySvyPoStringDbEntity.getTouchrelation() : dataBean.getDictItemCode());
        stratigraphySvyPointDbEntity.setTouchrelationName(touchrelation);
        stratigraphySvyPointDbEntity.setTouchredescription(touchredescription);
        stratigraphySvyPointDbEntity.setThickness(thickness);
        stratigraphySvyPointDbEntity.setStratigraphydescription(stratigraphydescription);
        stratigraphySvyPointDbEntity.setIsreversed("是".equals(isreversed) ? "1" : "0");
        stratigraphySvyPointDbEntity.setPhotoAiid(photoAiid);
        stratigraphySvyPointDbEntity.setPhotoviewingto(null == directionBean ?
                null == stratigraphySvyPoStringDbEntity ? "" : stratigraphySvyPoStringDbEntity.getPhotoviewingto() : directionBean.getDictItemCode());
        stratigraphySvyPointDbEntity.setPhotoviewingtoName(photoviewingto);
        stratigraphySvyPointDbEntity.setPhotographer(photographer);
        stratigraphySvyPointDbEntity.setDatasource(datasource);
        stratigraphySvyPointDbEntity.setIsmodifyworkmap("是".equals(ismodifyworkmap) ? "1" : "0");
        stratigraphySvyPointDbEntity.setIsinmap("是".equals(isinmap) ? "1" : "0");
        stratigraphySvyPointDbEntity.setLastangle(lastangle);
        stratigraphySvyPointDbEntity.setCommentInfo(remark);
        stratigraphySvyPointDbEntity.setPhotoAiid(photoAiid);
        if (Constant.IS_ON_LINE == 1) {
            stratigraphySvyPointDbEntity.setProjectId(projectId);
            stratigraphySvyPointDbEntity.setProjectName(projectName);
            stratigraphySvyPointDbEntity.setTaskName(taskName);
            stratigraphySvyPointDbEntity.setTaskId(taskId);
        }
        if (photoRecycleBuild.getSrcList().size() != 0) {
            String url = "";
            for (int i = 0; i < photoRecycleBuild.getSrcList().size(); i++) {
                if (TextUtils.isEmpty(url)) {
                    url = FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                } else {
                    url = url + "," + FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                }

            }
            stratigraphySvyPointDbEntity.setExtends7(url);
        }
        if (-1 != _id) {
            stratigraphySvyPointDbEntity.set_id(_id);
        }
        daoSession.insertOrReplace(stratigraphySvyPointDbEntity);

        CustomToast.showToast(this, "保存成功");
        finish();
    }

    public void submit() {
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();

        String id = etId.getText().toString().trim();
        String geologicalsvypointid = etGeologicalsvypointid.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String stratigraphyname = etStratigraphyname.getText().toString().trim();
        String strike = etStrike.getText().toString().trim();
        String dip = etDip.getText().toString().trim();
        String clination = etClination.getText().toString().trim();
        String touchrelation = tvTouchrelation.getText().toString().trim();
        String touchredescription = etTouchredescription.getText().toString().trim();
        String thickness = etThickness.getText().toString().trim();
        String stratigraphydescription = etStratigraphydescription.getText().toString().trim();
        String isreversed = tvIsreversed.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photoviewingto = tvPhotoviewingto.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String datasource = etDatasource.getText().toString().trim();
        String ismodifyworkmap = tvIsmodifyworkmap.getText().toString().trim();
        String isinmap = tvIsinmap.getText().toString().trim();
        String lastangle = etLastangle.getText().toString().trim();
        String emark = etRemark.getText().toString().trim();

        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }
        if (TextUtils.isEmpty(id)) {
            Toast("请录入地层点编号");
            return;
        }
        if (id.length() != 17){
            Toast("请录入正确的地层点编号");
            return;
        }
        if (TextUtils.isEmpty(fieldid)) {
            Toast("野外编号");
            return;
        }
        if (!TextUtils.isEmpty(strike)) {
            double d1 = Double.parseDouble(strike);
            if (d1 < 0 || d1 > 360) {
                Toast("走向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(strike)) {
            double d2 = Double.parseDouble(dip);
            if (d2 < 0 || d2 > 360) {
                Toast("实测倾向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(strike)) {
            double d3 = Double.parseDouble(clination);
            if (d3 < 0 || d3 > 90) {
                Toast("倾角角度值范围 0 ~ 90");
                return;
            }
        }


        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }

        DialogUtils.showIOSDialog(activity, "提示", "", "", "", ""
                , new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (null != myDialog)
                            myDialog.dismiss();
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        submit();
                        photoRecycleBuild.submitImage(photoRecycleBuild.getSrcList(), 1, new PhotoRecycleBuild.ImageCallBack() {
                            @Override
                            public void onCallBack(String url) {
                                StratigraphySvyPointActivity.this.urlArr = url;

                                JsonBuilder jsonBuilder = new JsonBuilder(StratigraphySvyPointActivity.this);
                                jsonBuilder.put("province", province);
                                jsonBuilder.put("city", city);
                                jsonBuilder.put("area", area);
                                jsonBuilder.put("lat", lon);
                                jsonBuilder.put("lon", lat);
                                jsonBuilder.put("town", buildingAddress);
                                jsonBuilder.put("type", type);
                                jsonBuilder.put("taskId", taskId);
                                jsonBuilder.put("projectId", projectId);
                                jsonBuilder.put("projectName", projectName);
                                jsonBuilder.put("taskName", taskName);
                                jsonBuilder.put("userId", SPUtil.get("userId", ""));
                                jsonBuilder.put("id", id);
                                jsonBuilder.put("geologicalsvypointid", geologicalsvypointid);
                                jsonBuilder.put("stratigraphyname", stratigraphyname);
                                jsonBuilder.put("strike", strike);
                                jsonBuilder.put("fieldid", fieldid);
                                jsonBuilder.put("dip", dip);
                                jsonBuilder.put("clination", clination);
                                jsonBuilder.put("touchrelation", null == dataBean ? "" : dataBean.getDictItemCode());
                                jsonBuilder.put("touchrelationName", null == dataBean ? "" : dataBean.getDictItemName());
                                jsonBuilder.put("touchredescription", touchredescription);
                                jsonBuilder.put("thickness", thickness);
                                jsonBuilder.put("stratigraphydescription", stratigraphydescription);
                                jsonBuilder.put("isreversed", "是".equals(isreversed) ? 1 : 0);
                                jsonBuilder.put("photoAiid", photoAiid);
                                jsonBuilder.put("photoviewingto", null == directionBean ? "" : directionBean.getDictItemCode());
                                jsonBuilder.put("photoviewingtoName", null == directionBean ? "" : directionBean.getDictItemName());
                                jsonBuilder.put("photographer", photographer);
                                jsonBuilder.put("datasource", datasource);
                                jsonBuilder.put("ismodifyworkmap", "是".equals(ismodifyworkmap) ? 1 : 0);
                                jsonBuilder.put("isinmap", "是".equals(isinmap) ? 1 : 0);
                                jsonBuilder.put("lastangle", lastangle);
                                jsonBuilder.put("commentInfo", emark);
                                jsonBuilder.put("extends7", urlArr);
                                jsonBuilder.put("createUser", SPUtil.get("userId", ""));
                                MyHttpClient
                                        .newBuilder()
                                        .post()
                                        .url(Api.HDD_START_POINT)
                                        .addParam(jsonBuilder.toJsonString())
                                        .build()
                                        .enqueue(new BaseCallBack<LoginBean>() {
                                            @Override
                                            public void onSuccess(LoginBean bean) {
                                                super.onSuccess(bean);
                                                if (bean.getCode() == 200) {
                                                    if (-1 != _id && null != stratigraphySvyPoStringDbEntity) {
                                                        try {
                                                            daoSession.delete(stratigraphySvyPoStringDbEntity);
                                                        } catch (Exception e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                    CustomToast.showToast(StratigraphySvyPointActivity.this, "提交成功");
                                                    finish();
                                                }
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                            }

                                            @Override
                                            public void onFailure(Call call, IOException e) {
                                                super.onFailure(call, e);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                                            }

                                            @Override
                                            public void onError(int code) {
                                                super.onError(code);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                                            }
                                        });
                            }
                        });
                    }
                }, "提交后不能再修改");

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case HYImageUtils.REQUEST_CODE_FROM_CAMERA:
                List<Uri> list_1 = new ArrayList<>();
                list_1.add(HYImageUtils.imageUriFromCamera);
                photoRecycleBuild.updataAdapter(list_1);
                break;
            case HYImageUtils.REQUEST_CODE_FROM_ALBUM:
                ArrayList<String> files = data.getStringArrayListExtra("files");
                if (files == null || files.size() == 0) {
                    return;
                }
                List<Uri> list_2 = new ArrayList<>();
                for (String file : files) {
                    list_2.add(Uri.fromFile(new File(file)));
                }
                photoRecycleBuild.updataAdapter(list_2);
                // submitImage(list_2, correctTypeListEntity.getFieldList().get(lastClickItemPosition));
                break;
        }
    }

    private void getHttpData(String type) {
        MyHttpClient
                .newBuilder()
                .get()
                .url(Api.HDD_START_POINT_TYPE + type)
                .build()
                .enqueue(new BaseCallBack<FaultTypeBean>() {
                    @Override
                    public void onSuccess(FaultTypeBean bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setFaultTypeCVD(bean, type);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                    }
                });
    }

    private List<FaultTypeBean.DataBean> dataBeans = new ArrayList<>();
    private FaultTypeBean.DataBean dataBean;
    private FaultTypeBean.DataBean directionBean;

    public void setFaultTypeCVD(FaultTypeBean bean, String type) {
        dataBeans.clear();
        dataBeans.addAll(bean.getData());
        String[] arr = new String[dataBeans.size()];
        for (int i = 0; i < dataBeans.size(); i++) {
            arr[i] = dataBeans.get(i).getDictItemName();
        }
        HYDialogUtils.showSingleChoiceItemAlertDialog(this, "选择", 0, arr
                , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (type) {
                            case "StraTouchTypeCVD":
                                dataBean = dataBeans.get(i);
                                tvTouchrelation.setText(dataBeans.get(i).getDictItemName());
                                break;
                            case "CVD-16-Direction":
                                directionBean = dataBeans.get(i);
                                tvPhotoviewingto.setText(dataBeans.get(i).getDictItemName());
                                break;
                        }
                        dialogInterface.dismiss();
                    }
                });
    }

    public void getDetailHttp() {
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        String url = Api.HDD_START_POINT + "/" + uuid;
        MyHttpClient
                .newBuilder()
                .get()
                .url(url)
                .build()
                .enqueue(new BaseCallBack<StratigraphySvyPointEntity>() {
                    @Override
                    public void onSuccess(StratigraphySvyPointEntity bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setDetailData(bean);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(StratigraphySvyPointActivity.this, "网络异常");
                    }
                });
    }

    private void setDetailData(StratigraphySvyPointEntity bean) {
        tabTitleBuilder.setDetailText(bean.getData().getProvince(), bean.getData().getCity()
                , bean.getData().getArea(), bean.getData().getLat(), bean.getData().getLon(), bean.getData().getTown());

        etId.setText(StringUtil.isNull(bean.getData().getId()));
        etGeologicalsvypointid.setText(StringUtil.isNull(bean.getData().getGeologicalsvypointid()));
        etFieldid.setText(StringUtil.isNull(bean.getData().getFieldid()));
        etStratigraphyname.setText(StringUtil.isNull(bean.getData().getStratigraphyname()));
        etStrike.setText(StringUtil.isNull(bean.getData().getStrike()));
        etDip.setText(StringUtil.isNull(bean.getData().getDip()));
        etClination.setText(StringUtil.isNull(bean.getData().getClination()));
        tvTouchrelation.setText(StringUtil.isNull(bean.getData().getTouchrelationName()));
        etTouchredescription.setText(StringUtil.isNull(bean.getData().getTouchredescription()));
        etThickness.setText(StringUtil.isNull(bean.getData().getThickness()));
        etStratigraphydescription.setText(StringUtil.isNull(bean.getData().getStratigraphydescription()));
        tvIsreversed.setText("1".equals(bean.getData().getIsreversed()) ? "是" : "否");
        etPhotoAiid.setText(StringUtil.isNull(bean.getData().getPhotoAiid()));
        tvPhotoviewingto.setText(StringUtil.isNull(bean.getData().getPhotoviewingtoName()));
        etPhotographer.setText(StringUtil.isNull(bean.getData().getPhotographer()));
        etDatasource.setText(StringUtil.isNull(bean.getData().getDatasource()));
        tvIsmodifyworkmap.setText("1".equals(bean.getData().getIsmodifyworkmap()) ? "是" : "否");
        tvIsinmap.setText("1".equals(bean.getData().getIsinmap()) ? "是" : "否");
        etLastangle.setText(StringUtil.isNull(bean.getData().getLastangle()));
        etRemark.setText(StringUtil.isNull(bean.getData().getCommentInfo()));
        photoRecycleBuild.setHttpUrl(bean.getData().getExtends7());
    }

    private void setDetail(StratigraphySvyPointDbEntity bean) {
        this.stratigraphySvyPoStringDbEntity = bean;
        tabTitleBuilder.setDetailText(bean.getProvince(), bean.getCity()
                , bean.getArea(), bean.getLat(), bean.getLon(), bean.getTown());

        etId.setText(StringUtil.isNull(bean.getId()));
        etGeologicalsvypointid.setText(StringUtil.isNull(bean.getGeologicalsvypointid()));
        etFieldid.setText(StringUtil.isNull(bean.getFieldid()));
        etStratigraphyname.setText(StringUtil.isNull(bean.getStratigraphyname()));
        etStrike.setText(StringUtil.isNull(bean.getStrike()));
        etDip.setText(StringUtil.isNull(bean.getDip()));
        etClination.setText(StringUtil.isNull(bean.getClination()));
        tvTouchrelation.setText(StringUtil.isNull(bean.getTouchrelationName()));
        etTouchredescription.setText(StringUtil.isNull(bean.getTouchredescription()));
        etThickness.setText(StringUtil.isNull(bean.getThickness()));
        etStratigraphydescription.setText(StringUtil.isNull(bean.getStratigraphydescription()));
        tvIsreversed.setText("1".equals(bean.getIsreversed()) ? "是" : "否");
        etPhotoAiid.setText(StringUtil.isNull(bean.getPhotoAiid()));
        tvPhotoviewingto.setText(StringUtil.isNull(bean.getPhotoviewingtoName()));
        etPhotographer.setText(StringUtil.isNull(bean.getPhotographer()));
        etDatasource.setText(StringUtil.isNull(bean.getDatasource()));
        tvIsmodifyworkmap.setText("1".equals(bean.getIsmodifyworkmap()) ? "是" : "否");
        tvIsinmap.setText("1".equals(bean.getIsinmap()) ? "是" : "否");
        etLastangle.setText(StringUtil.isNull(bean.getLastangle()));
        etRemark.setText(StringUtil.isNull(bean.getCommentInfo()));
        if (!TextUtils.isEmpty(bean.getExtends7())) {
            String[] arr = bean.getExtends7().split(",");
            List<Uri> list = new ArrayList<>();
            for (int i = 0; i < arr.length; i++) {
                File file = new File(arr[i]);
                Uri uri = Uri.fromFile(file);
                list.add(uri);
            }
            photoRecycleBuild.updataAdapter(list);
        }
    }
}
